/*
 * @Description: 
 * @Author: Wen
 * @Date: 2024-12-03 09:13:20
 * @LastEditors: Wen
 * @LastEditTime: 2024-12-03 09:16:55
 * 太棒了，又坚持了一天
 */
package com.briup.web;

import com.briup.pojo.Student;
import com.briup.pojo.StudentWithAddress;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RequestMapping("/path")
// 类级别的RequestMapping
@RestController//Controller必须要添加的
public class PathController {
    @RequestMapping("/test")//处理请求路径和方法
    public String test(){
        System.out.println(("in test()"));
        return "Hello,PathController,test()";
    }
    @RequestMapping(path={"/hello","/hi"})//处理请求路径和方法
    //@RequestMapping(value={"/hello","/hi"})//处理请求路径和方法
    public String hello(){
        System.out.println(("in hello()"));
        return "Hello,PathController,hello()";
    }

    //指定请求方法
    //@RequestMapping(value="/method",method = RequestMethod.POST)
    @RequestMapping(value="/method",method = {RequestMethod.POST,RequestMethod.GET})
    //通过method属性指定请求方法
    public String method(){
        System.out.println(("in method()"));
        return "method,PathController,method()";
    }

    //获取请求参数
    @RequestMapping(value="/getParams",method = {RequestMethod.POST,RequestMethod.GET })
    //通过method属性指定请求方法
    public String getParams(HttpServletRequest request){
        String name =request.getParameter("name");
        String ageStr =request.getParameter("age");
        int age = Integer.parseInt(ageStr);
        System.out.println("name"+name);
        System.out.println("age"+age);
        System.out.println(("in getParams()"));
        return "ok";
    }

    //参数获取方式
    @RequestMapping("/simpleParam")
    public  String simpleParam(String name, Integer age){
        System.out.println("name:" + name );
        System.out.println("age:" + age );
        return  "ok";
    }

    @RequestMapping("/simpleParam2")
    public  String simpleParam2(@RequestParam("username") String name, Integer age){
        System.out.println("name:" + name );
        System.out.println("age:" + age );
        return  "ok";
    }

    //实体参数-请求参数名称要和pojo属性名一致，否则无法封装
    @RequestMapping("/simplePojo")
    public  String simplePojo(Student stu){
        System.out.println( stu );
        return  "ok";
    }

    //嵌套实体参数-请求参数名称要和pojo属性名一致，否则无法封装
    @RequestMapping("/complexPojo")
    public  String complexPojo(StudentWithAddress stu){
        System.out.println( stu );
        return  "ok";
    }

    //嵌套实体参数-请求参数名称要和pojo属性名一致，否则无法封装
    @RequestMapping("/arrayParam")
    public  String arrayParam(String[] likes){
        System.out.println( likes );
        return  "ok";
    }
}